/*
 * @Author: your name
 * @Date: 2021-04-11 18:24:16
 * @LastEditTime: 2021-04-29 20:54:11
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /first_flutter_app/lib/indexPage/indePage.dart
 */
import 'package:first_flutter_app/constant/dataInfo.dart';
import 'package:first_flutter_app/controller/orderPageController.dart';
import 'package:first_flutter_app/controller/tablePageController.dart';
import 'package:first_flutter_app/views/indexPage/table.dart';
import 'package:first_flutter_app/util/IconText.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class dianCanIndexPage extends StatelessWidget {

  var tableCount = 0;

  @override
  Widget build(BuildContext context) {
    tableCount = OrderController.oc.tableList.length;
    return _dianCan();
  }

  Widget _dianCan() {
    return Expanded(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          _topTitle(),
          _tableWrap(),
        ],
      ),
    );
  }

  Widget _containerButtonIconText(String textStt, Icon icon) {
    return Container(
      margin: EdgeInsets.all(2),
      child: ElevatedButton(
        child: IconText(
          "$textStt",
          icon: icon,
          iconSize: 15.0,
          direction: Axis.horizontal,
          style: TextStyle(
            color: Colors.black54,
            fontSize: 12,
          ),
        ),
        style: ButtonStyle(
          // padding: MaterialStateProperty.all(EdgeInsets.all(10)),
            backgroundColor: MaterialStateProperty.all<Color>(Colors.white)),
        onPressed: () {},
      ),
    );
  }

  Widget _leftTop() {
    return Expanded(
        flex: 4,
        child: Container(
          margin: EdgeInsets.only(left: ScreenUtil().setSp(60)),
          child: Row(
            children: [
              _containerButtonIconText("联台", Icon(Icons.copy_sharp)),
              _containerButtonIconText(
                  "空闲桌台($tableCount)", Icon(Icons.table_rows)),
              _containerButtonIconText("快速入门", Icon(Icons.book))
            ],
          ),
        ));
  }

  Widget _horizontalTextShow() {
    return Container(
      child: Row(children: [
        Container(
          margin: EdgeInsets.fromLTRB(0, 0, 5, 0),
          alignment: Alignment.center,
          child: CircleAvatar(radius: 6.0, backgroundColor: Colors.orange),
        ),
        Text("下单桌"),
        Container(
          margin: EdgeInsets.fromLTRB(5, 0, 5, 0),
          alignment: Alignment.center,
          child: CircleAvatar(radius: 6.0, backgroundColor: Colors.purple),
        ),
        Text("结账桌"),
      ]),
    );
  }

  // 右边头部展示
  Widget _rightTop() {
    return Expanded(
        flex: 5,
        child: Row(
          children: [
            _horizontalTextShow(),
            _containerButtonIconText("自取", Icon(Icons.add_shopping_cart)),
            _containerButtonIconText("核销", Icon(Icons.confirmation_num)),
            _containerButtonIconText("更多功能", Icon(Icons.more)),
          ],
        ));
  }

  // 头部展示
  Widget _topTitle() {
    return Flex(
      direction: Axis.horizontal,
      children: [
        _leftTop(),
        GetBuilder<OrderController>(
            builder: (_) => Visibility(
              visible: !OrderController.oc.showOrderDetails,
              child: _rightTop(),
          )
        )
      ],
    );
  }

  // 组装桌台列表
  List<Widget> _getTableList() {
    // ignore: deprecated_member_use
    List<Widget> aList = OrderController.oc.tableList.asMap().entries.map((item) {
      return Container(
        child: tableShow(tableInfo: item.value, tableIndex: item.key),
      );
    }).toList();
    return aList;
  }

  // 桌台展示
  Widget _tableWrap() {
    return Expanded(
      child: SingleChildScrollView(
        child: Wrap(
          spacing: 9,
          runSpacing: 9,
          children: this._getTableList(),
        ),
      ),
    );
  }
}

// class _dianCanIndexPageState extends State<dianCanIndexPage> {
//
// }
